'''
元素等待的3种方法：
(1)显式等待是针对某一个元素进行相关等待判定；
①WebDriverWait()
(2)隐式等待不针对某一个元素进行等待，全局元素等待。
①implicitly_wait()	默认参数的单位为秒。
(3)sleep休眠方法
①sleep()
'''
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
# from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from time import sleep
chrome_location = r'D:\chrom browser\chrome-win\chrome.exe'
options = webdriver.ChromeOptions()
options.binary_location = chrome_location
dr = webdriver.Chrome(options=options)
dr.get(r'https://www.baidu.com/')
dr.maximize_window()
# dr.implicitly_wait(30)  #隐式等待
# # sleep(3)
# dr.find_element(By.ID,'kw').send_keys('aaa')
sleep(3)
#针对百度按钮进行显式等待
su_loc=(By.ID,'su')
ele=WebDriverWait(dr,30,0.5).until(EC.visibility_of_element_located(su_loc))   #是否可见
# WebDriverWait(dr,30,0.5).until(EC.presence_of_element_located(su_loc))   #是否存在
ele.click()
sleep(3) #死等
dr.quit()